<!--
 * @Author: 孙开源 && sunkaiyuan@namenode.cn
 * @Date: 2023-09-16 10:29:47
 * @LastEditors: 孙开源 && sunkaiyuan@namenode.cn
 * @LastEditTime: 2023-09-16 14:17:06
 * @Description: 
 * 
-->
<template>
  <el-dialog draggable overflow v-model="visible" :title="'结账'" :width="500" destroy-on-close @closed="$emit('closed')">
    <el-card>
      <scTable ref="table" :data="data" height="auto" hideDo>
        <el-table-column label="年" prop="year" min-width="60"></el-table-column>
        <el-table-column label="月" prop="month" min-width="60"></el-table-column>
        <el-table-column label="操作" prop="status_id" width="70">
          <template #default="scope">
            <el-button type="primary" :disabled="isSaveing" :class="scope.row.status_id == 0 ? '' : 'red'"
              @click="closeBtn(scope.row.status_id == 0 ? 1 : 0, scope.row.year, scope.row.month)">{{
                scope.row.status_id == 0 ? '结账' : '取消'
              }}</el-button>
          </template>
        </el-table-column>
      </scTable>
    </el-card>
  </el-dialog>
</template>

<script>

export default {
  emits: ["success", "closed"],
  components: {},
  data() {
    return {
      data: [],
      isSaveing: false,
      visible: false
    }
  },
  mounted() {
    this.getlist();
  },
  methods: {

    //显示
    open() {
      this.visible = true;
      return this;
    },
    //表单提交方法
    async closeBtn(status_id, year, month) {

      this.isSaveing = true;

      var res = await this.$API.finance.close.set.post({ status_id: status_id, year: year, month: month });
      if (res.code == 200) {
        await this.getlist()
        this.$message.success("操作成功");
      }
      this.isSaveing = false;

    },
    async getlist() {
      var res = await this.$API.finance.close.list.get();
      if (res.code == 200) {
        this.data = res.data
      }
    },
  },
};
</script>
<style></style>
